SET(SOURCES ld.cpp main.S)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-Wall")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wall")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-static")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static")

ADD_EXECUTABLE(ld-duckos.so ${SOURCES})
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/libraries/ld/ld-duckos.ld)
ADD_DEPENDENCIES(ld-duckos.so libc)
SET_TARGET_PROPERTIES(ld-duckos.so PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}")
TARGET_LINK_LIBRARIES(ld-duckos.so gcc libduck_static libexec_static)
INSTALL(TARGETS ld-duckos.so RUNTIME DESTINATION lib)